alert('ScenePlayer.js loaded');

var video;

function ScenePlayer() {

};

function playVideo(){
	alert("------------------ Player video  SRC = "+VideoName);
	video = document.getElementById("vidWindow");
	video.load();
	video.play();
}

ScenePlayer.prototype.initialize = function () {
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here
	// scene HTML and CSS will be loaded before this function is called
};

ScenePlayer.prototype.handleShow = function (data) {
	alert("ScenePlayer.handleShow()");
	// this function will be called when the scene manager show this scene
	sf.scene.hide('ToolBar');
	$('#VideoDiv video source').attr('src', 'videos/'+VideoName);
	CurrentScene = "Player";

	playVideo();
	$("#VideoDiv video").bind("ended", function() {
			alert("/////////////////// plop");
		    PlayVideo = false;
			sf.scene.hide('Player');
			sf.scene.show(''+NextScene+'');
			sf.scene.focus(''+NextScene+'');
			
	});
};

ScenePlayer.prototype.handleHide = function () {
	alert("ScenePlayer.handleHide()");
	// this function will be called when the scene manager hide this scene
	video.pause();
	//video.stopVideo();
};

ScenePlayer.prototype.handleFocus = function () {
	alert("ScenePlayer.handleFocus()");
	// this function will be called when the scene manager focus this scene
};

ScenePlayer.prototype.handleBlur = function () {
	alert("ScenePlayer.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
};

ScenePlayer.prototype.handleKeyDown = function (keyCode) {
	alert("ScenePlayer.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	switch (keyCode) {
		case sf.key.LEFT:
			break;
		case sf.key.RIGHT:
			break;
		case sf.key.UP:
			break;
		case sf.key.DOWN:
			break;
		case sf.key.ENTER:
			PlayVideo = false;
			sf.scene.hide('Player');
			if (!NoHide){
				alert("+++++++++++++++++++++++++++++++++++++++++++++++ show");
				sf.scene.show(''+NextScene+'');
			}
			sf.scene.focus(''+NextScene+'');			
			break;
		case sf.key.RETURN:
			PlayVideo = false;
			event.preventDefault();
			sf.scene.hide('Player');
			sf.scene.show('Menu');
			sf.scene.focus('Menu');
			break;
		default:
			alert("handle default key event, key code(" + keyCode + ")");
			break;
	}
};
